<?php

namespace App\Models\Personnel;

use App\Models\Pay\Gongjijin;
use App\Models\Pay\Gongling;
use App\Models\Pay\Gongshang;
use App\Models\Pay\OthersPerson;
use App\Models\Pay\Shiye;
use App\Models\Pay\Yanglao;
use App\Models\Pay\Yiliao;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use App\Models\Model;

class Personnel extends Model
{
    protected $table = 'akbus_personnel';

    protected $fillable = [
        'name',
        'graduated_at',
        'name',
        'status',
        'is_injured',
        'departure_at',
        'sort',
        'phone',
        'native_place',
        'nation',
        'political',
        'married',
        'education',
        'work_at',
        'major',
        'graduated_school',
        'graduated_at',
        'join_at',
        'positive_at',
        'contract_expire_at',
        'IDCard_url',
        'ID_photo_url',
        'IDCard',
        'IDCard_expire_at',
        'IDCard_address',
        'residential_address',
        'endowment_insurance_status',
        'endowment_insurance_payment_at',
        'medical_insurance_status',
        'medical_insurance_payment_at',
        'unemployment_insurance_status',
        'unemployment_insurance_payment_at',
        'injured_insurance_status',
        'injured_insurance_payment_at',
        'maternity_insurance_status',
        'maternity_insurance_payment_at',
        'type',
        'note',
    ];

    /**
     * 不可批量赋值的属性。
     *
     * @var array
     */
    protected $guarded = [
    ];

    /**
     * 类型转化
     *
     * @var array
     */
    protected $casts = [
    ];

    /**
     * 隐藏的字段
     *
     * @var array
     */
    protected $hidden = [
    ];

    public function getEndowmentInsuranceStatusAttribute($value): string
    {
        return (string) $value;
    }

    public function getMedicalInsuranceStatusAttribute($value): string
    {
        return (string) $value;
    }

    public function getUnemploymentInsuranceStatusAttribute($value): string
    {
        return (string) $value;
    }

    public function getInjuredInsuranceStatusAttribute($value): string
    {
        return (string) $value;
    }

    public function getMaternityInsuranceStatusAttribute($value): string
    {
        return (string) $value;
    }

    /**
     * 行政人员信息
     */
    public function adminInfo(): HasOne
    {
        return $this->hasOne(PersonnelAdmin::class, 'personnel_id');
    }

    /**
     * 驾驶员信息
     */
    public function driverInfo(): HasOne
    {
        return $this->hasOne(PersonnelDriver::class, 'personnel_id');
    }

    /**
     * 离职信息
     */
    public function departure(): hasMany
    {
        return $this->hasMany(PersonnelDeparture::class, 'personnel_id');
    }

    /**
     * 工伤信息
     */
    public function injured(): hasMany
    {
        return $this->hasMany(PersonnelInjured::class, 'personnel_id');
    }

    /**
     * 工作经历
     */
    public function workExperience(): HasMany
    {
        return $this->hasMany(PersonnelWorkExperience::class, 'personnel_id');
    }

    /**
     * 教育经历
     */
    public function eduExperience(): HasMany
    {
        return $this->hasMany(PersonnelEduExperience::class, 'personnel_id');
    }

    /**
     * 家庭成员
     */
    public function family(): HasMany
    {
        return $this->hasMany(PersonnelFamily::class, 'personnel_id');
    }

    /**
     * 附件上传
     */
    public function file(): HasMany
    {
        return $this->hasMany(PersonnelFile::class, 'personnel_id');
    }

    public function yanglao(): HasMany
    {
        return $this->hasMany(Yanglao::class, 'personnel_id');
    }

    public function yiliao(): HasMany
    {
        return $this->hasMany(Yiliao::class, 'personnel_id');
    }

    public function shiye(): HasMany
    {
        return $this->hasMany(Shiye::class, 'personnel_id');
    }

    public function gongshang(): HasMany
    {
        return $this->hasMany(Gongshang::class, 'personnel_id');
    }

    public function gongling(): HasMany
    {
        return $this->hasMany(Gongling::class, 'personnel_id');
    }

    public function gongjijin(): HasMany
    {
        return $this->hasMany(Gongjijin::class, 'personnel_id');
    }

    public function others(): HasMany
    {
        return $this->hasMany(OthersPerson::class, 'personnel_id');
    }
}
